package com.demo.dao.impl;

import com.demo.bean.Emp;
import com.demo.dao.EmpDao;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.ibatis.support.SqlMapClientDaoSupport;

import java.util.List;

/**
 * @author : mafan
 * @date : 2021-02-03 14:38
 **/
public class EmpDaoImpl extends SqlMapClientDaoSupport implements EmpDao {

    @Override
    public List<Emp> findEmp(String ename) {
        System.out.println("EmpDaoImpl.findEmp");
        try {
            List emp = getSqlMapClientTemplate().queryForList("findEmp", ename);
            System.out.println("EmpDaoImpl.findEmp" + emp);
            return emp;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    @Override
    public boolean saveEmp(Emp emp) {
        System.out.println("EmpDaoImpl.saveEmp");
        try {
            getSqlMapClientTemplate().insert("saveEmp", emp);
            return true;
        } catch (DataAccessException e) {
            e.printStackTrace();
            return false;
        }
    }

    @Override
    public List<Emp> findAll(Emp emp) {
        List list = getSqlMapClientTemplate().queryForList("findAll");
        return list;
    }

    @Override
    public Integer deleteEmp(Integer empno) {
        try {
            getSqlMapClientTemplate().delete("deleteEmp", empno);
            return 1;
        } catch (Exception e) {
            e.printStackTrace();
            return 0;
        }
    }

    @Override
    public boolean updateEmp(Emp emp) {
        System.out.println("EmpDaoImpl.updateEmp");

        try {
            getSqlMapClientTemplate().update("updateEmp", emp);
            return true;
        } catch (Exception e) {
            e.printStackTrace();
            return false;
        }
    }
}
